/**
 * 
 */
package cn.edu.hstc.ui.fragment;

import java.util.List;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import cn.edu.hstc.app.App;
import cn.edu.hstc.bean.ScoreTable;
import cn.edu.hstc.bean.ScoreTable.Score;
import cn.edu.hstc.bean.utils.ScoreUtils;
import cn.edu.hstc.common.L;
import cn.edu.hstc.ui.JwglMain;

/**
 * @Description 用户成绩展示
 * @author act262
 * @version 1.0
 * @since 2014-4-30 下午5:32:32
 * 
 */
public class UserScore extends BaseFragment {
	private static UserScore sFragment = null;

	private final String TAG = UserScore.class.getSimpleName();

	/**
	 * @param bundle
	 * @return
	 */
	public static UserScore getInstance(Bundle bundle) {
		if (null == sFragment) {
			sFragment = new UserScore();
		}
		sFragment.setArguments(bundle);
		return sFragment;
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		L.d(TAG, "onCreate");

		// new GetScoreTask().execute(App.getUser().getStudentId(),
		// App.getUser().getName());
		// 查找学期成绩
		new GetScoreTask().execute(App.getUser().getStudentId(), App.getUser().getName(), "2011-2012", "1");
	}

	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return super.onCreateView(inflater, container, savedInstanceState);
	}

	private final class GetScoreTask extends AsyncTask<String, Integer, ScoreTable> {

		@Override
		protected ScoreTable doInBackground(String... params) {
			L.d(TAG, "GetScoreTask doInBackground");

			return ScoreUtils.getScoreTable(JwglMain.sHttpClient, params);
		}

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			L.d(TAG, "GetScoreTask start");
		}

		@Override
		protected void onPostExecute(ScoreTable result) {
			super.onPostExecute(result);
			L.d(TAG, "GetScoreTask end");

			if (null != result) {
				List<Score> scoreList = result.getScoreList();
				for (Score p : scoreList) {
					L.d(TAG, p.toString());
				}
			}

		}

	}
}
